<?php

/**
 * cart actions.
 *
 * @package    test_cart
 * @subpackage cart
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class cartActions extends sfActions
{

    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request)
    {
        $cc = new prestaPaypal(sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . 'prestaPaypalPlugin' . DIRECTORY_SEPARATOR . 'sdk' . DIRECTORY_SEPARATOR . 'lib');

// Setup API's credentials
// Your PayPal ID or an email address associated with your PayPal account. Email addresses must be confirmed.
        $cc->setUserName('mgw_mo_1348564952_biz_api1.yahoo.com');
        $cc->setPassword('1348564975');
// API signature
// How to get a signature ? https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_NVPAPIBasics
        $cc->setSignature('A8cV1ApaNH1vfs4NBUP698WrfWGNACeD6ROme6Rw0z5NiDHLVZ6B1xP-');
// Usefull in development environment
        $cc->setTestMode(true);

// Warning : you must be in an action method for this line
        sfContext::getInstance()->getConfiguration()->loadHelpers('Url');

// A URL to which the payer's browser is redirected if payment is cancelled
//        echo url_for('cart/cancel', true);
        $cc->setCancelURL('http://www.google.com/');

// The URL to which the payer's browser is redirected after completing the payment
        $cc->setReturnURL('http://www.google.com/');

// Amount payement incl. taxes
        $cc->setTransactionTotal('39.95');
        $cc->setTransactionDescription('Registration');

// The express url well-formed
        echo $goto = $cc->GetExpressUrl();
        if ($goto)
        {
            $this->redirect($goto);
        }
        else
        {
            return $this->renderText('Error: ' . $cc->getErrorString());
        }
    }

    public function executeDone()
    {
        return $this->renderText('Done');
    }

    public function executeCancel()
    {
        return $this->renderText('Cancel');
    }

    public function executeDirectPayment()
    {
        // Setup API's credentials
        $cc = new prestaPaypal(sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . 'prestaPaypalPlugin' . DIRECTORY_SEPARATOR . 'sdk' . DIRECTORY_SEPARATOR . 'lib');


// Setup API's credentials
// Your PayPal ID or an email address associated with your PayPal account. Email addresses must be confirmed.
        $cc->setUserName('mgw_mo_1348564952_biz_api1.yahoo.com');
        $cc->setPassword('1348564975');
// API signature
// How to get a signature ? https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_NVPAPIBasics
        $cc->setSignature('A8cV1ApaNH1vfs4NBUP698WrfWGNACeD6ROme6Rw0z5NiDHLVZ6B1xP-');
// Usefull in development environment
        $cc->setTestMode(true);
// Amount payement incl. taxes
        $cc->setTransactionTotal('2000');
// A description for the transaction
        $cc->setTransactionDescription('desc ya desc desc');

// Client information :
        $cc->setBillingFirstName('Micheal');
        $cc->setBillingLastName('Gooo');
        $cc->setBillingStreet1('ada asdasd asdasd');
        $cc->setBillingStreet2('sssd aaaaaaa aaaaaaaaaaaaaaaaaa');
        $cc->setBillingCity('fffff ffffff fffffffff');
        $cc->setBillingState('aaas asdasd asdasd ad asd asd  sad asdas');
        $cc->setBillingZip(12345);

        $cc->setCardType('Visa');
        $cc->setCardNumber('4010788758345284');
        $cc->setCardVerificationNumber('564');
        $cc->setCardExpirationMonth(9);
        $cc->setCardExpirationYear(2017);
        $cc->setBuyerIP($_SERVER['REMOTE_ADDR']);

// Do payement
        if (!$cc->chargeDirect())
        {
           return $this->renderText('Error: ' .$cc->getErrorString());
        }
        else
        {
            return $this->renderText('Done :) ');
        }
    }

}
